package com.deliinsns.sys.listener;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.deliinsns.sys.util.PropertyUtils;
public class BasicDataListener implements ServletContextListener {

	static Logger logger = Logger.getLogger(BasicDataListener.class.getName());
	public void contextInitialized(ServletContextEvent sce) {
		//初始化系统,加载系统信息
		ServletContext servletContext = sce.getServletContext();
		String configFilePath = servletContext.getRealPath("WEB-INF/config/config.properties");
		String codeDescFilePath = servletContext.getRealPath("WEB-INF/config/codeDesc.properties");
		Properties config= PropertyUtils.getProperties(configFilePath);
		Properties codeDesc= PropertyUtils.getProperties(codeDescFilePath);
		for(Enumeration e=config.propertyNames(); e.hasMoreElements();){  
		    String key=(String) e.nextElement();  
		   // System.out.println(key+"===>"+config.getProperty(key));  
		    servletContext.setAttribute(key, config.getProperty(key));
		}  
		
		servletContext.setAttribute("codeDesc", codeDesc);
		  //ApplicationContext context = BeanManager.getContext();
//		   // 总结：监听器在spring容器加载之前初始化，所以程序运行到这里时spring对象还没有被初始化，当然context为空咯！呵呵
//		  HibernateTemplate hibernateTemplate=(HibernateTemplate) context.getBean("hibernatetemplate");
//	      List basicInfo=hibernateTemplate.find("from Basicattr");//初始化workState
//	      System.out.println("大小："+basicInfo.size());
//				      List buildingList=hibernateTemplate.find("from Building");//初始化workState
//				      //List managerList=hibernateTemplate.find("from Manager");//初始化workState
//			          event.getServletContext().setAttribute("basicInfo",basicInfo );
//			          event.getServletContext().setAttribute("buildingList",buildingList );
//			         // event.getServletContext().setAttribute("managerList",managerList );
//			          event.getServletContext().setAttribute("sysState",1);

		 
		 
	}
	public void contextDestroyed(ServletContextEvent sce){}
	
}
